package com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.impl;

import com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.JsonMessageHandler;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.Impl.PlayerNicknameJsonWebSocketMessage;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.WebSocketMessageTypeEnum;
import com.cicc.beergamevirtualsimulationsystem.entity.RoomInfoManager;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

@Component
public class PlayerNicknameJsonMessageHandler implements JsonMessageHandler<PlayerNicknameJsonWebSocketMessage> {
    @Override
    public void handle(WebSocketSession session, PlayerNicknameJsonWebSocketMessage message) {
        String roomId = (String)session.getAttributes().get("roomId");
        String userId = (String)session.getAttributes().get("userId");
        RoomInfoManager.addPlayerName(roomId,userId,message.getMessage());


    }

    @Override
    public String type() {
        return WebSocketMessageTypeEnum.PLAYER_NICKNAME.getValue();
    }

    @Override
    public Class<PlayerNicknameJsonWebSocketMessage> getMessageClass() {
        return PlayerNicknameJsonWebSocketMessage.class;
    }
}
